package com.control.qct.businesssteward.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.adapter.NewReplenishmentAdapter;
import com.control.qct.businesssteward.base.BaseFragment;
import com.control.qct.businesssteward.model.NewReplenishmentModel;
import com.control.qct.businesssteward.utils.CustomCodeUtils;
import com.control.qct.businesssteward.utils.DialogUtil;
import com.control.qct.businesssteward.utils.EditTextUtils;
import com.control.qct.businesssteward.utils.ScreenUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/1/16 0016.
 */

public class NewReplenishmentFragment extends BaseFragment {
    @BindView(R.id.iv_goods_style)
    ImageView mIvGoodsStyle;
    @BindView(R.id.et_barcode)
    EditText mEtBarcode;
    @BindView(R.id.iv_sure)
    ImageView mIvSure;
    @BindView(R.id.iv_scan)
    ImageView mIvScan;
    @BindView(R.id.rv_order_goods)
    RecyclerView mRvReplenishmentOrderGoods;
    @BindView(R.id.tv_replenishment_num)
    TextView mTvReplenishmentNum;
    @BindView(R.id.rl_replenishment_order)
    RelativeLayout mRlReplenishmentOrder;
    @BindView(R.id.iv_clear)
    ImageView mIvClear;

    private List<NewReplenishmentModel> mNewReplenishmentModelList = new ArrayList<>();
    private NewReplenishmentAdapter mNewReplenishmentAdapter;
    private View mPurchaseNumView;
    private Dialog mPurchaseNumDialog;

    @Override
    protected View initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        return inflater.inflate(R.layout.fragment_new_replenishment, container, false);
    }


    @Override
    protected void initView(View view) {
        activity.setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.getSupportFragmentManager().popBackStack();
            }
        });
        activity.setRightIcon("");
        EditTextUtils.isEditContent(mEtBarcode,mIvClear);
        for (int i = 0; i < 6; i++) {
            mNewReplenishmentModelList.add(new NewReplenishmentModel());
        }
        mRvReplenishmentOrderGoods.setLayoutManager(new LinearLayoutManager(activity));
        mNewReplenishmentAdapter = new NewReplenishmentAdapter(mNewReplenishmentModelList);
        mRvReplenishmentOrderGoods.setAdapter(mNewReplenishmentAdapter);
        mNewReplenishmentAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                setPurchaseNumDialog();
            }
        });
    }


    /**
     * 采购数量
     */
    private void setPurchaseNumDialog() {
        mPurchaseNumView = View.inflate(activity, R.layout.dialog_change_price,
                null);
        mPurchaseNumDialog = DialogUtil.getDialog(activity, true, mPurchaseNumView, ScreenUtil
                .getScreenWidthPix(activity));
        TextView tvGoodsName = mPurchaseNumView.findViewById(R.id.tv_goods_name);
        TextView tvDialogTitle = mPurchaseNumView.findViewById(R.id.tv_dialog_title);
        TextView tvGoodsCode = mPurchaseNumView.findViewById(R.id.tv_goods_code);
        TextView tvGoodsPrice = mPurchaseNumView.findViewById(R.id.tv_goods_price);
        EditText etChangePrice = mPurchaseNumView.findViewById(R.id.et_change_price);
        tvDialogTitle.setText("采购数量");
        etChangePrice.setHint("请输入采购数量");
        mPurchaseNumView.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPurchaseNumDialog.dismiss();
            }
        });
        mPurchaseNumView.findViewById(R.id.tv_sure).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPurchaseNumDialog.dismiss();
            }
        });
    }

    @OnClick({R.id.iv_goods_style, R.id.iv_sure, R.id.iv_scan, R.id.rl_replenishment_order,R.id.iv_clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_goods_style://品类
                break;
            case R.id.iv_clear://清除文字
                mEtBarcode.setText("");
                break;
            case R.id.iv_sure://确定搜索
                break;
            case R.id.iv_scan://扫描
                CustomCodeUtils.getInstance(activity).startToCaptureActivity(this);
                break;
            case R.id.rl_replenishment_order://补货单
                activity.replaceFragment(R.id.fl_content, new ReplenishmentOrderFragment(), true);
                break;
        }
    }
}
